﻿Imports System.Data.OleDb

Public Class addHotel
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"

        If f_Picture.HasFile Then
            f_Picture.SaveAs(Request.MapPath("Pictures") & "/" & newFileName)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("travelConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into hotels(HotelName,Location,Stars,Description,HotelUrl,Pictures,Traveller) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_HotelName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_Location.Text)
        cmd.Parameters.AddWithValue("@f3", rbl_Stars.SelectedValue)
        cmd.Parameters.AddWithValue("@f4", tb_Description.Text)
        cmd.Parameters.AddWithValue("@f5", tb_HotelUrl.Text)
        cmd.Parameters.AddWithValue("@f6", "Pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f7", User.Identity.Name)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class